<html>
<head>
<TITLE>CSE5317/4305 Project #7</TITLE>
</head>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<center>
<H1>CSE5317/4305 Project #7 (Instruction Selection)</H1>
Due Thursday May 7 at 11:59pm<p>
Worth 14% of your project grade
</center>
<p>
<hr>
<p>
This is the final stage of your project in which you are asked to translate IRs into MIPS code.
For this project, the goal is to generate <b>correct</b>
MIPS code that runs and computes the correct results of a PCAT program.
<p>
You should modify the <tt>mips</tt> method in the file <a href="pcat/Mips.gen">Mips.gen</a>
that generates MIPS code from the IR and returns the register that
will hold the result.
A simple register allocation algorithm is provided.
It uses a pool of temporary registers, which is reset at the beginning of each IR statement.
Even though there is a danger of running out of registers for complex expressions,
it is not expected to be so for the given test programs.
It's very important to recycle registers (ie, to put registers back to pool after they are used).
The rule is, if you don't return a register from a mips method, it should be recycled.
The MIPS code for the Call IR is also provided because it requires to
store the used registers in the run-time stack before the call and to restore them after
the call. If you don't do so, there will be interference between the temporary registers
of caller and callee. This means that all temporary registers are caller-save.
<p>
You need to run your parser against all <tt>tests/*.pcat</tt> files.
For example:
<pre>
run 7 hello
</pre>
It will generate MIPS code from <tt>tests/hello.pcat</tt> into the file <tt>tests/hello.s</tt>
and will load and execute the code using the SPIM emulator.
You also need to compare your output with that of the solution:
<pre>
solution 7 hello
</pre>
Don't expect to get exactly the same output because the solution uses very few optimizations.
<p>
The SPIM emulator can be found in <a href="http://www.cs.wisc.edu/~larus/spim.html">http://www.cs.wisc.edu/~larus/spim.html</a>. 
You can install it on your PC. If you are doing the project on omega, do:
<pre>
wget http://www.cs.wisc.edu/~larus/SPIM/spim.tar.gz
tar xfz spim.tar.gz
cd spim-7.3/spim
make
</pre>
<p>
One clever way to start this project is to temporarily remove the <tt>Mips.gen</tt> file and run, eg.
<pre>
run 7 hello
</pre>
that will convert your IR code into MIPS using the solution and will run it using SPIM.
When you make sure that your IR code generates the correct MIPS using the solution, then
you can start writting your own <tt>Mips.gen</tt> code to generate the same MIPS code.
<p>
After ensuring that your program compiles and executes correctly,
cleanup your <tt>pcat</tt> directory using
<tt>
clean
</tt>
Then, if you are using Linux, archive your file using <tt>tar cvf pcat.tar pcat</tt>.
If you are using Windows, zip the whole directory into the file <tt>pcat.zip</tt>.
Then submit your file (<tt>pcat.tar</tt> or <tt>pcat.zip</tt>) here:
<p>
<form enctype="multipart/form-data" action="https://lambda.uta.edu/cgi-bin/php/handin.php" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
    <input type="hidden" name="class" value="cse5317" />
    <input type="hidden" name="assignment" value="proj7" />
Submit this file: <input name="userfile" type="file" size="50"/><br/>
    <input type="submit" value="Send File" />
</form>
<p>

<hr>
<P>
<ADDRESS>Last modified: 01/14/09 by <A HREF="http://lambda.uta.edu/">Leonidas Fegaras</A></ADDRESS>
